package studyguide.ch09.graphics;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;

public class GraphicsCanvasA extends Canvas {

	private final String TEXT_SAMPLE = "Sample text.";
	
	protected void paint(Graphics g) {
		// Clear screen
		g.setColor(255, 255, 255);
		g.fillRect(0, 0, getWidth(), getHeight());
		
		// Base point will be the middle of the screen
		int x = getWidth() / 2;
		// Vertical distance between objects:
		int yStep = getHeight() / 4;
		int y = 0;
		
		g.setColor(0, 0, 0); // Black

		// Draw lines to show the reference points:
		g.drawLine(x, 0, x, getHeight());
		
		// Centered string:
		y += yStep;
		g.drawLine(0, y, getWidth(), y);
		g.drawString(TEXT_SAMPLE, x, y, Graphics.BASELINE|Graphics.HCENTER);
		
		// Top/left
		y += yStep;
		g.drawLine(0, y, getWidth(), y);
		g.drawString(TEXT_SAMPLE, x, y, Graphics.TOP|Graphics.LEFT);

		// Bottom/Right
		y += yStep;
		g.drawLine(0, y, getWidth(), y);
		g.drawString(TEXT_SAMPLE, x, y, Graphics.BOTTOM|Graphics.RIGHT);
		
	}

}
